package com.jisf.driver.controller;

import com.jisf.driver.entity.vo.AllotMenusVo;
import com.jisf.driver.entity.vo.MenuListVo;
import com.jisf.driver.response.IErrorCode;
import com.jisf.driver.response.Result;
import com.jisf.driver.service.IRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jisf
 * @since 2022-04-08
 */
@RestController
@RequestMapping("/driver/roleMenu")
public class RoleMenuController {

    @Autowired
    private IRoleMenuService iRoleMenuService;

    @GetMapping("delete/menu")
    @PreAuthorize("hasAnyAuthority('roleMenu:delete:menu')")
    public Result<?> deleteMenu(@RequestParam Integer roleId, @RequestParam Integer menuId){
        IErrorCode iErrorCode = iRoleMenuService.deleteRoleMenu(roleId, menuId);
        List<MenuListVo> roleMenus = iRoleMenuService.findRoleMenus(roleId);
        return Result.ok(iErrorCode, roleMenus);
    }

    @PostMapping("allotMenus")
    @PreAuthorize("hasAnyAuthority('roleMenu:allotMenus')")
    public Result<?> allotMenus(@RequestBody AllotMenusVo allotMenusVo){
        IErrorCode iErrorCode = iRoleMenuService.allotMenus(allotMenusVo);
        return Result.ok(iErrorCode);
    }


}
